<?php 
function deleteFile($dir) {
    if(substr($dir, strlen($dir)-1, 1) != '/') { 
        $dir .= '/'; 
    }
    if($handle = opendir($dir)) { 
        while($obj = readdir($handle)) { 
            if($obj != '.' && $obj != '..') { 
                if(is_dir($dir.$obj)) { 
                    if(!deleteFile($dir.$obj)) {
                        echo $dir.$obj."<br />";
                        return false;
                    }
                }
                elseif(is_file($dir.$obj)) { 
                    if(!unlink($dir.$obj)) {
                        echo $dir.$obj."<br />";
                        return false;
                    }
                }
            }
        }
        closedir($handle); 
        if(!@rmdir($dir)) {
            echo $dir.'<br />';
            return false;
        }
        return true;
    }
    return true;
}
if ((isset($_GET['id'])) && ($_GET['id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM galleryplug WHERE id=%s",
                       GetSQLValueString($_GET['id'], "int"));
					   
  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($deleteSQL, $konek) or die(mysql_error());
  
  $deleteSQL2 = sprintf("DELETE FROM galleryplug_data WHERE id_module=%s",
                       GetSQLValueString($_GET['id'], "int"));
					   
  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($deleteSQL2, $konek) or die(mysql_error());
  
  deleteFile('../g-konten/fm/gallery/'.$_GET['id'].'/');

  $deleteGoTo = "add_module.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
 ?>
	
	 <script language="javascript">
  	<!--
     	    alert('Delete Success')
			window.location = "home.php?page=pluginview&p=<?php echo $_GET['p'] ?>&root=add_module.php";
			
   	--></script>
	<?php
}

?>
